package com.javathread.th1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


public class NewThread {
	public static class UseRun implements Runnable{

		@Override
		public void run() {
			System.out.println("UseRun Runnable is running");
		}
		
	}
	
	public static class UseCall implements Callable<String>{

		@Override
		public String call() throws Exception {
			System.out.println(Thread.currentThread().getName()+"UseCall Callable is running");
			//SleepTools.second(2);
			return Thread.currentThread().getName();
		}
	}
	
  public static void main(String[] args) throws InterruptedException, ExecutionException {
	
	  UseRun useRun = new UseRun();
	  UseCall useCall = new UseCall();
	  
	  Thread t2 = new Thread() {

		@Override
		public void run() {
			try {
			  for (int i =0;i<10;i++) {
				  FutureTask<String> futureTask = new FutureTask<String>(useCall);
				  new Thread(futureTask).start();
				  
					System.out.println(futureTask.get());
				
			  	}
			  } catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ExecutionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		  
	  };
	  
	  		t2.start();
	  
	  
	  new Thread(useRun).start();
	  
	  Thread t = new Thread(useRun);
	  t.interrupt();
	  
  }
}
